//
//  XinJianKeHuWenBenYuTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/3/8.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "XinJianKeHuWenBenYuTableViewCell.h"

@implementation XinJianKeHuWenBenYuTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    _insertTextView.delegate = self;
    

}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    // 获取当前文本框中的文本
    if(_maxLength == 0){
        return YES;
    }
    NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
    
    // 设置最大字符长度
    NSUInteger maxLength = _maxLength;
    
    _numLabel.text = [NSString stringWithFormat:@"%ld/%ld",textView.text.length,_maxLength];
    
    // 检查是否超过最大长度
    if (newText.length <= maxLength) {
        return YES; // 允许输入
    } else {
        return NO; // 超过最大长度，禁止输入
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    [textView resignFirstResponder];
    
    if(_textViewEndEditingBlock){
        _textViewEndEditingBlock(textView.text);
    }
    
}


- (void)setMaxLength:(NSInteger)maxLength{
    _maxLength = maxLength;
    if(_maxLength == 0){
        _numLabel.hidden = YES;
    }else{
        _numLabel.hidden = NO;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
